package com.zhumo.sz.mapper;


import com.zhumo.sz.entity.subway.*;
import com.zhumo.sz.provider.BatchInsertProvider;
import com.zhumo.sz.provider.BatchNestCorrespondentProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 地铁业务Mapper层
 */
@Mapper
public interface SubwayMapper {

    /**
     * 插入地铁流量信息
     */
    @InsertProvider(type = BatchNestCorrespondentProvider.class,method = "batchInsert")
    int insertSubwayTraffic(@Param("list")List<SubwayGateSwipeDetail> gatePayment);


    /**
     * 批量插入,2021年深圳地铁线路信息 详细信息
     */
    @InsertProvider(type = BatchNestCorrespondentProvider.class,method = "batchInsert")
    int insertSubwayStationInfoDO(@Param("list") List<SubwayStationInfo> list);


    /**
     * 插入地铁线路信息
     */
    @InsertProvider(type = BatchInsertProvider.class,method = "batchInsert")
    int insertSubwayLineInfo(@Param("list") List<SubwayLine> subwayLineList);

    /**
     * 插入闸机信息
     */
    @InsertProvider(type = BatchInsertProvider.class,method = "batchInsert")
    int insertGate(@Param("list") List<SubwayGateInfo> subwayGateInfos);


    /**
     * 插入地铁公交中转信息
     */
    @InsertProvider(type = BatchInsertProvider.class,method = "batchInsert")
    int insertSubwayTransitTransfer(@Param("list")List<SubwayTransitTransfer> transitTransferList);

    /**
     * 查询地铁线路信息
     */
    @Select("select line_code,line_name,version from sz_traffic.subway_station_info group by line_code,line_name,version;")
    List<SubwayLine> getSubwayLineInfo();

    /**
     * 获取地铁站点信息
     */
    @Select("select * from sz_traffic.subway_station_info where site_code != '265027';")
    List<SubwayStationInfo> getAllSubwayStationInfo();

    @Select("select * from subway_gate_info;")
    List<SubwayGateInfo> getAllSubwayGateInfo();

    /**
     * 查询所有地铁流量订单 SubwayGateSwipeDetail
     */
    @Select("select order_id from sz_traffic.subway_gate_swipe_detail;")
    List<String> getAllSubwayTrafficOrder();


    /**
     * 查询指定地铁线路的所有地铁站
     */
    @Select("select * from sz_traffic.subway_station_info where line_code = #{lineCode} and site_code != '265027';")
    List<SubwayStationInfo> getStationByLine(@Param("lineCode") String lineCode);

    /**
     * 查询所有地铁线
     */

    @Select("select line_code from sz_traffic.subway_line")
    List<String> getAllLine();

    /**
     * 根据站点编码获取所有闸机编码
     */
    @Select("select * from subway_gate_info where gate_station_code = #{gateStationCode};")
    List<SubwayGateInfo> getGateBySite(@Param("gateStationCode") String gateStationCode);

    /**
     * 获取所有地铁出口
     */
    @Select("SELECT \n" +
            "\tsite_code,\n" +
            "\tgroup_concat(site_out separator '-') as site_out\n" +
            "FROM (select site_code,site_out FROM subway_transit_transfer GROUP BY site_code,site_out) as t\n" +
            "GROUP BY site_code;")
    List<SubwayTransitTransfer> getAllGateWithSite();

    /**
     * 获取地铁站交通服务信息
     */
//    @MapKey("siteCode") // 告诉Mybatis使用peopleId作为Map的key
    @Select("select transportation from sz_traffic.subway_station_info where site_code = #{siteCode} group by transportation;")
    String  getTransportationBySite(@Param("siteCode") String siteCode);

    @Select("select site_code from sz_traffic.subway_station_info group by site_code;")
    List<String> getAllStations();


}
